package com.woniu.postbar.service.impl;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.common.config.PostQueueConfig;
import com.woniu.common.constant.PostBarConstant;
import com.woniu.common.entity.Result;
import com.woniu.common.entity.ResultCode;
import com.woniu.common.exception.LifeException;
import com.woniu.common.utils.JwtUtil;
import com.woniu.postbar.entity.dto.PostAdminDTO;
import com.woniu.postbar.mapper.PostAdminMapper;
import com.woniu.postbar.pojo.PostAdmin;
import com.woniu.postbar.service.IPostAdminService;
import com.woniu.user.feignClient.UserFeignClient;
import com.woniu.user.pojo.User;
import io.jsonwebtoken.Claims;
import net.bytebuddy.implementation.bytecode.Throw;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wu
 * @since 2023-05-20
 */
@Service
public class PostAdminServiceImpl extends ServiceImpl<PostAdminMapper, PostAdmin> implements IPostAdminService {

    @Autowired
    private PostAdminMapper postAdminMapper;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public void addAdminPost(PostAdminDTO postAdmin) {
        if (postAdmin.getUserType() == PostBarConstant.USER_TYPE){
            postAdminMapper.addAdminPost(postAdmin);
            String title = postAdmin.getTitle();
            rabbitTemplate.convertAndSend(PostQueueConfig.POST_LIKE_EXCHANGE, PostQueueConfig.POST_LIKE_ROUTING_KEY, title);
        }else {
            throw new LifeException(ResultCode.USER_TYPE_ERROR.getMessage());
        }
    }
}
